package com.test.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/11/28 17:39
 */
@Component
public class Dog implements ApplicationContextAware {
    private ApplicationContext context;

    public Dog() {
        System.out.println("dog constructor...");
    }

    //对象创建并赋值之后调用
    @PostConstruct
    public void init() {
        System.out.println("Dog...@PostConstruct");
    }

    //容器移除对象之前调用
    @PreDestroy
    public void destory() {
        System.out.println("Dog...@PreDestroy");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }
}
